﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace DeviceControlClient
{
    internal class ClientConfig
    {          
        public string Ip { get; set; }
        public int Port { get; set; }
        public ClientConfig()
        {
            Ip = "127.0.0.1";
            Port = 3333;          
            SetProperiesValue();
        }

        private void SetProperiesValue()
        {
            Type type = this.GetType();
            PropertyInfo[] Properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            foreach (PropertyInfo p in Properties)
            {
                string name = p.Name;               
                if (p.PropertyType == typeof(bool) || p.PropertyType == typeof(System.Boolean))
                {
                    p.SetValue(this, IniFile.LoadBoolenValue(name, true), null); 
                }
                else if (p.PropertyType == typeof(int))
                {
                    p.SetValue(this, IniFile.LoadInt32Value(name, 300), null); 
                }
                else
                {
                    p.SetValue(this, IniFile.IniValue(name, ""), null); 
                }
            }         
        }
    }
}
